﻿<ContentControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                xmlns:controls="clr-namespace:Corina.Controls.Win;assembly=Corina.Controls.Win"
                xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                xmlns:localViewmodel="clr-namespace:Corina.Win.ServerHub.Viewmodels;assembly=Corina.Win.ServerHub"
                xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                HorizontalContentAlignment="Stretch"
                VerticalContentAlignment="Stretch"
                d:DesignHeight="480"
                d:DesignWidth="800"
                mc:Ignorable="d">
    <Grid>
        <Border Background="{DynamicResource COLOR_LIGHTGRAY}" CornerRadius="5" />
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="auto" />
                <RowDefinition Height="auto" />
                <RowDefinition />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Label HorizontalAlignment="Center" Content="{Binding AppTitle}" />
            <StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
                <Button Command="{Binding MinizedCommand, Mode=OneWay}" Style="{DynamicResource style_button_min}" />
                <Button Command="{Binding CloseCommand, Mode=OneWay}" Style="{DynamicResource style_button_close}" />
            </StackPanel>

            <Grid Grid.Row="1" MinHeight="41">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" MinWidth="100" />
                    <ColumnDefinition />
                    <ColumnDefinition Width="Auto" MinWidth="50" />
                </Grid.ColumnDefinitions>

                <Rectangle Grid.ColumnSpan="3"
                           Height="1"
                           Margin="0,1"
                           VerticalAlignment="Bottom"
                           Fill="{DynamicResource COLOR_DARKGRAY}" />
                <Grid Margin="0,1">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="6" />
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>
                    <Rectangle Fill="OrangeRed" />

                    <Path Grid.Column="1"
                          Width="24"
                          Height="24"
                          Margin="12,0"
                          HorizontalAlignment="Left"
                          Data="{Binding Icon,
                                         Converter={StaticResource KeyToPathGeometryConverter},
                                         Mode=OneWay}"
                          Fill="Black"
                          RenderTransformOrigin="0.5,0.5"
                          Stretch="Uniform">
                        <Path.RenderTransform>
                            <TransformGroup>
                                <TransformGroup.Children>
                                    <RotateTransform Angle="0" />
                                    <ScaleTransform ScaleX="1" ScaleY="1" />
                                </TransformGroup.Children>
                            </TransformGroup>
                        </Path.RenderTransform>
                    </Path>
                </Grid>

                <ListBox Grid.Column="1"
                         Background="Transparent"
                         BorderThickness="0"
                         ItemContainerStyle="{DynamicResource style_mainnavi_item}"
                         ItemsSource="{Binding ContractViewmodels}"
                         SelectedItem="{Binding SelectedViewmodel}">
                    <ListBox.ItemsPanel>
                        <ItemsPanelTemplate>
                            <VirtualizingStackPanel Orientation="Horizontal" />
                        </ItemsPanelTemplate>
                    </ListBox.ItemsPanel>
                </ListBox>

                <StackPanel Grid.Column="2"
                            Margin="12,0"
                            VerticalAlignment="Center"
                            Orientation="Horizontal">
                    <TextBlock TextDecorations="none">
                        <Hyperlink Command="{Binding HomeCommand}" TextDecorations="none">首页</Hyperlink>
                    </TextBlock>

                    <TextBlock Visibility="{Binding IsEnabled, Converter={StaticResource BooleanToVisibilityConverter}}">
                        <Run Text="  | " />
                        <Run Text="{Binding CurrentAccount.Name}" />
                    </TextBlock>
                </StackPanel>
            </Grid>

            <Frame Grid.Row="2"
                   Margin="12"
                   NavigationUIVisibility="Hidden"
                   Source="{Binding ViewUrl}"
                   Visibility="{Binding IsSelectedNull,
                                        Converter={StaticResource BooleanToVisibilityInverseConverter}}" />

            <Grid Grid.Row="2"
                  Margin="12"
                  Visibility="{Binding IsSelectedNull,
                                       Converter={StaticResource BooleanToVisibilityConverter}}">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition />
                    <ColumnDefinition Width="300" />
                </Grid.ColumnDefinitions>

                <Grid Grid.Column="1">

                    <Grid.DataContext>
                        <localViewmodel:ServerViewmodel />
                    </Grid.DataContext>

                    <Grid.RowDefinitions>
                        <RowDefinition Height="auto" />
                        <RowDefinition />
                    </Grid.RowDefinitions>
                    <Rectangle Grid.RowSpan="2"
                               Width="1"
                               HorizontalAlignment="Left"
                               Fill="{DynamicResource COLOR_DARKGRAY}"
                               SnapsToDevicePixels="True" />
                    <StackPanel>
                        <!--
                            <Grid Margin="6,0,0,0">
                            <Grid.ColumnDefinitions>
                            <ColumnDefinition />
                            <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>
                            <Label Content="IP地址：" />
                            <ItemsControl Grid.Column="1" ItemsSource="{Binding CurrentIPAddress}">
                            <ItemsControl.ItemTemplate>
                            <DataTemplate>
                            <Label Grid.Column="1"
                            HorizontalContentAlignment="Right"
                            Content="{Binding }" />
                            </DataTemplate>
                            </ItemsControl.ItemTemplate>
                            </ItemsControl>
                            </Grid>
                        -->
                        <Expander Margin="6,0,0,0" Header="IP地址">
                            <ItemsControl Grid.Column="1" ItemsSource="{Binding CurrentIPAddress}">
                                <ItemsControl.ItemTemplate>
                                    <DataTemplate>
                                        <Label Grid.Column="1"
                                               HorizontalContentAlignment="Right"
                                               Content="{Binding }" />
                                    </DataTemplate>
                                </ItemsControl.ItemTemplate>
                            </ItemsControl>
                        </Expander>
                        <Grid Margin="6,12,0,12">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>
                            <Label Content="端口号：" />
                            <Label Grid.Column="1" Content="{Binding Port}" />
                        </Grid>
                        <Rectangle Height="1"
                                   Fill="{DynamicResource COLOR_DARKGRAY}"
                                   SnapsToDevicePixels="True" />

                        <Grid Margin="06,12,0,12">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>
                            <Label Content="当前在线：" />
                            <Label Grid.Column="1" Content="{Binding ClientCount}" />
                        </Grid>

                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>
                            <Path Width="20"
                                  Height="20"
                                  Margin="12,0"
                                  HorizontalAlignment="Left"
                                  Data="{Binding Converter={StaticResource StringToPathGeometryConverter},
                                                 Mode=OneWay,
                                                 Source={StaticResource ICON_CLOCK}}"
                                  Fill="Black"
                                  RenderTransformOrigin="0.5,0.5"
                                  Stretch="Uniform">
                                <Path.RenderTransform>
                                    <TransformGroup>
                                        <TransformGroup.Children>
                                            <RotateTransform Angle="0" />
                                            <ScaleTransform ScaleX="1" ScaleY="1" />
                                        </TransformGroup.Children>
                                    </TransformGroup>
                                </Path.RenderTransform>
                            </Path>
                            <TextBlock Grid.Column="1" Margin="6,0">
                                <Run Text="{Binding RunSeconds, Mode=OneWay, Converter={StaticResource SecondsToReadableStringConverter}}" />
                            </TextBlock>
                        </Grid>
                        <Grid Margin="6,12,0,12">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition />
                                <ColumnDefinition Width="12" />
                                <ColumnDefinition />
                            </Grid.ColumnDefinitions>
                            <Button Margin="6,0"
                                    Command="{Binding StartCommand,
                                                      Mode=OneWay}"
                                    Content="启动" />
                            <Button Grid.Column="2"
                                    Margin="6,0"
                                    Command="{Binding StopCommand,
                                                      Mode=OneWay}"
                                    Content="停止" />
                        </Grid>
                        <Rectangle Height="1"
                                   Fill="{DynamicResource COLOR_DARKGRAY}"
                                   SnapsToDevicePixels="True" />
                    </StackPanel>

                    <ItemsControl Grid.Row="1"
                                  Margin="12"
                                  ItemsSource="{Binding Top10Client}">
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition />
                                        <ColumnDefinition Width="auto" />
                                    </Grid.ColumnDefinitions>
                                    <Label Content="{Binding Address}" />
                                    <Label Grid.Column="1" Content="{Binding EntryTime, StringFormat=\{0:HH:hh:ss\}}" />
                                </Grid>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>
                </Grid>
            </Grid>

            <TextBlock Grid.Row="3"
                       Margin="12,0"
                       HorizontalAlignment="Left"
                       VerticalAlignment="Center">
                <Run Text="Version:" />
                <Run Text="{Binding ApplicationVersion, Mode=OneWay}" />
            </TextBlock>

            <TextBlock Grid.Row="3"
                       Margin="12,0"
                       HorizontalAlignment="Right"
                       VerticalAlignment="Center">
                <Run Text="公网IP:" />
                <Run Text="{Binding PublicIPAddress, Mode=OneWay}" />
            </TextBlock>

            <Label Grid.Row="3"
                   HorizontalAlignment="Center"
                   Content="DAMON 2013" />
        </Grid>
        <controls:PromptWindow Title="{Binding PromptHeader}"
                               Margin="0"
                               HorizontalContentAlignment="Stretch"
                               VerticalContentAlignment="Stretch"
                               CloseCommand="{Binding HidePromptCommand}"
                               HorizontalWindowAlignment="Center"
                               VerticalWindowAlignment="Center"
                               Visibility="{Binding ShowPromptWindow,
                                                    Converter={StaticResource BooleanToVisibilityConverter}}"
                               WindowHeight="240"
                               WindowWidth="400">
            <Grid Margin="12,0">
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <TextBlock HorizontalAlignment="Left"
                           Text="{Binding PromptContent}"
                           TextWrapping="Wrap" />
                <Button Grid.Row="1"
                        Width="60"
                        HorizontalAlignment="Right"
                        Command="{Binding HidePromptCommand}"
                        Content="确定"
                        Style="{StaticResource ButtonStyle}" />
            </Grid>
        </controls:PromptWindow>
    </Grid>
</ContentControl>